﻿/*
 *   ArrayTests.cs
 *   Copyright (c) 2011 - BitFox Software and Ricardo Federico Villafañes
 *   Contact: federvillaf@hotmail.com
 *   
 *   Licensing: This product is covered by Microsoft Reciprocal License (MS-RL)
 *              see https://bitfoxeval.codeplex.com/license
*/

using System;
using System.IO;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

using BitFox.Evaluator;

namespace TestEvaluator
{
    /// <summary>
    /// Tests that probe the emulator is doing its basic work (checking handling of fox's types)
    /// </summary>
    [TestClass]
    public class ArrayTests
    {
        /// <summary>
        /// The evaluator on which to do tests
        /// </summary>
        Evaluator eval = new Evaluator();

        /// <summary>
        /// Empty ctor
        /// </summary>
        public ArrayTests()
        {
        }

        /// <summary>
        /// The context under which tests are runned.
        ///</summary>
        public TestContext TestContext { get; set; }

        /// <summary>
        /// Helper method that removes files and directories used to test array functions
        /// </summary>
        void RemoveTestFileData()
        {
            try { File.Delete(".\\tdd\\subdd\\text2.txt"); } catch { }
            try { File.Delete(".\\tdd\\subdd\\sample.asc"); } catch { }
            try { File.Delete(".\\tdd\\sample.asc"); } catch { }
            try { File.Delete(".\\tdd\\text2.txt"); } catch { }
            try { File.Delete(".\\tdd\\textfile1.txt"); } catch { }
            try { Directory.Delete("..\\tdd\\subdd"); } catch {}
            try { Directory.Delete("..\\tdd"); } catch { }
        }

        /// <summary>
        /// Test than simple fields are correctly handled either by reflection or IResolvable
        /// </summary>
        [TestMethod]
        public void TestADIR()
        {
            // Creates some directory/files to test pattern.
            RemoveTestFileData();
            Directory.CreateDirectory(".\\tdd");
            File.WriteAllLines(".\\tdd\\textfile1.txt", new string[] { "l1", "l2" });
            File.WriteAllLines(".\\tdd\\text2.txt", new string[] { "l1", "l2" });
            File.WriteAllLines(".\\tdd\\sample.asc", new string[] { "l1", "l2" });
            Directory.CreateDirectory(".\\tdd\\subdd");
            File.WriteAllLines(".\\tdd\\subdd\\text2.txt", new string[] { "l1", "l2" });
            File.WriteAllLines(".\\tdd\\subdd\\sample.asc", new string[] { "l1", "l2" });

            // Do the tests
            bool goUp = false;
            try
            {
            }
            finally 
            {
                if (goUp) Directory.SetCurrentDirectory("..");
                RemoveTestFileData(); 
            }
        }
    }
}
